<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>分配床位</title>
		<link rel="shortcut icon" href="img/logo.jpg">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link href="css/bootstrap-responsive.css" rel="stylesheet" />
		<link href="css/bootstrap.css" rel="stylesheet" media="screen">
	</head>

	<body>
		<legend>床位分配</legend>

		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<ul class="breadcrumb">
						<li>
							<a href="#">主页</a> <span class="divider">/</span>
						</li>
						<li>
							<a href="#">床位管理</a> <span class="divider">/</span>
						</li>
						<li>
							<a href="http://127.0.0.1/view/distribute_beds/bed.html#">床位分配</a>
							<span class="divider">/</span>
						</li>
						<li class="active">
							分配详情</a>
						</li>
					</ul>
				</div>
			</div>
		</div>

		<article>
			<form class="form-horizontal" @submit.prevent="">
				<div class="control-group">
					<label class="control-label" for="inputEmail">住户：</label>
					<div class="controls">
						<input input v-model="params.elderId" type="text" placeholder="住户姓名">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">床位：</label>
					<div class="controls">
						<input input v-model="params.bedId" type="text" placeholder="床位编号">
					</div>
				</div>

				<div class="control-group">
					<label class="control-label">分配人：</label>
					<div class="controls">
						<input input v-model="params.createUserId" type="text" placeholder="分配人">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">入住时间：</label>
					<div class="controls">
						<input input v-model="params.createTime" type="date" placeholder="入住时间">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">退住时间：</label>
					<div class="controls">
						<input input v-model="params.endTime" type="date" placeholder="退住时间">
					</div>
				</div>
				<div class="control-group">
					<label class="control-label">退住原因：</label>
					<div class="controls">
						<input input v-model="params.leaveReason" type="text" placeholder="退住原因">
					</div>
				</div>

				<div class="control-group">
					<div class="controls">
						<button class="btn" :disabled="actionBtnDisabled" @click.prevent="udBedsEvt">修改</button>
						<button class="btn" :disabled="actionBtnDisabled" @click.prevent="sureDel">删除</button>
					</div>
				</div>
			</form>
		</article>

		<script src="../../common/axios.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../common/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="http://code.jquery.com/jquery.js"></script>
		<script src="js/bootstrap.js"></script>
		<script src="../../common/jun/yi.shakeit.js"></script>
		<script src="../../common/jun/yi.toast.js"></script>
		<script>
			let getQueryString = function(id) {
				var reg = new RegExp('(^|&)' + id + '=([^&]*)(&|$)', 'i');
				var r = window.location.search.substr(1).match(reg);
				if(r != null) {
					return unescape(r[2]);
				}
				return null;
			};
			const vm = new Vue({
				el: "body>article",
				data: {
					params: {},
					resp: {
						message: null
					},
					actionBtnDisabled: false
				},
				mounted() {
						axios({
							method: 'get',
							url: `http://127.0.0.1:80/api/elderbed/${getQueryString('id')}`,
						}).then(resp => {
							this.params = resp.data;
						});
					},
				methods: {
					"udBedsEvt": function() {
						this.actionBtnDisabled = true;
						let mymessage = confirm("您确定修改吗？");
						if(mymessage) {
							axios.put(`http://127.0.0.1:80/api/elderbed/mod/${getQueryString('id')}`, this.params)
								.then(function(resp) {
									if(resp.code === "ok") {
										toast("床位分配成功！");
										setTimeout(function() {
											location.href = "bed.html";
										}, 3000);

									} else {
										toast(resp.message);
									}
								}).finally(function() {
									vm.actionBtnDisabled = false;
								});
						}
					},
					"sureDel": function() {
						this.actionBtnDisabled = true;
						let a = confirm("您确定删除吗？");
						if(a) {
							axios.delete(`http://127.0.0.1:80/api/elderbed/del/${getQueryString('id')}`, this.params)
								.then(function(resp) {
									if(resp.code === "ok") {
										toast("删除成功！");
										setTimeout(function() {
											location.href = "bed.html";
										}, 3000);

									} else {
										toast(resp.message);
									}
								}).finally(function() {
									vm.actionBtnDisabled = false;
								});
						}
					},

				}
			});
		</script>

	</body>

</html>

<!--axios.delete(`http://127.0.0.1:80/api/elderbed/del/${getQueryString('id')}`, this.params)
								.then(function(resp) {
									if(resp.code === "ok") {
										alert("删除成功");
									} else {
										alert("系统繁忙...");
									}
								}).finally(function() {
									vm.actionBtnDisabled = false;
								}),-->